package com.mwl;

import com.pojo.User;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @Auther: mwl
 * @Date: 2025-07-25 - 07 -25 -2:37
 * @Description: com.mwl
 * @Version: 1.0
 */
public class jdbcDemo {

    public static void main(String[] args) throws Exception{

//        Class.forName("com.mysql.jdbc.Driver");
        Class.forName("com.mysql.cj.jdbc.Driver");

        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mybatis", "root", "123456");

        String sql = "SELECT * from user";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        ResultSet resultSet = preparedStatement.executeQuery();

        while (resultSet.next()){
            User user = new User();
            user.setId(resultSet.getInt("id"));
            user.setUsername(resultSet.getString("username"));
            user.setBirthday(resultSet.getDate("birthday"));
            user.setSex(resultSet.getString("sex"));
            user.setAddress(resultSet.getString("address"));
            System.out.println(user);
        }

        resultSet.close();
        preparedStatement.close();
        connection.close();

    }


}
